<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    {% load static %}
    <script src="{% static 'js/jquery-3.7.1.min.js' %}"></script>
</head>
<body>
    {% load static %}
    <img src="/static/imgs/th.jpg">
    <img src="{% static 'images/th2.jpg' %}"> 
    <div class="wrapper">
        <form>
            {% csrf_token %}
            <div>
                用户名: <input type="text" name="userName">
            </div>
            <div>
                密码: <input type="text" name="password">
            </div>
            <div>
               <input type="submit" value="登录">
            </div>
        </form>
    </div>
<script>
    $(function(){
        $(':button').click(function () {
            //获取所有表单参数
            let data = $('form').serialize()
            $.post('/news/login2/', data)
                .then(res => {
                    if (res.code == 200) {
                        location.href = '/news/newslist/'
                    }
                    alert(res.msg)
                })
                .catch(err => console.log(err)) //失败响应结果
        })
    })
    </script>
</body>
</html>